package com.job.client.common.result;

import lombok.Data;

//统一的返回类
@Data
public class ResponseResult<T> {
    private Integer code;
    private String message;
    private T data;
//    构造私有化，方式外部创建该类实例
    private ResponseResult(){};
//    无参返回，默认=200
    public static ResponseResult OkResult(){
        ResponseResult result=new ResponseResult();
        result.setCode(AppHttpCode.SUCCESS.getCode());
        result.setMessage(AppHttpCode.SUCCESS.getMsg());
        return result;
    }
//    无参返回，AppHttpCode用户设置
    public static ResponseResult OkResult(AppHttpCode appHttpCode){
        ResponseResult result=new ResponseResult();
        result.setCode(appHttpCode.getCode());
        result.setMessage(appHttpCode.getMsg());
        result.setData(null);
        return result;
    }
//   有参返回，默认返回200
    public static<T> ResponseResult<T> OkResult(T data){
        ResponseResult<T> result=new ResponseResult<>();
        result.setCode(AppHttpCode.SUCCESS.getCode());
        result.setMessage(AppHttpCode.SUCCESS.getMsg());
        result.setData(data);
        return  result;
    }
//    有参返回，返回用户自定义code
    public static<T> ResponseResult<T> OkResult(T data,AppHttpCode appHttpCode){
        ResponseResult<T> result=new ResponseResult<>();
        result.setCode(appHttpCode.getCode());
        result.setMessage(appHttpCode.getMsg());
        result.setData(data);
        return  result;
    }
//    失败的默认方法 201 无参返回
    public static ResponseResult ErrorResult(){
        ResponseResult result=new ResponseResult();
        result.setCode(AppHttpCode.FAIL.getCode());
        result.setMessage(AppHttpCode.FAIL.getMsg());
        result.setData(null);
        return result;
    }
//    失败的方法 自定义code 无参返回
    public static ResponseResult ErrorResult(AppHttpCode appHttpCode){
        ResponseResult result=new ResponseResult();
        result.setCode(appHttpCode.getCode());
        result.setMessage(appHttpCode.getMsg());
        result.setData(null);
        return  result;
    }
//   失败的放法 自定义coe 并且返回相应假数据
    public static<T> ResponseResult<T> ErrorResult(T data,AppHttpCode appHttpCode){
        ResponseResult<T> result=new ResponseResult<>();
        result.setCode(appHttpCode.getCode());
        result.setMessage(appHttpCode.getMsg());
        result.setData(data);
        return  result;
    }
//    失败的方法 自定义code和message，午参返回
public static ResponseResult ErrorResult(String message,Integer code){
    ResponseResult result=new ResponseResult();
    result.setCode(code);
    result.setMessage(message);
    result.setData(null);
    return result;
}
}
